package com.chang.auto;

import com.chang.Token.TokenTemplate;
import com.chang.interceptor.TokenWebConfig;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @program: erp-api
 * @description:
 * @author: chang
 * @create: 2025-02-15 11h
 **/
@AutoConfiguration(after = TokenAutoConfigure.class)
@EnableConfigurationProperties(TokenInterceptorProperties.class)
@ConditionalOnClass(value={HandlerInterceptor.class, WebMvcConfigurer.class})
@ConditionalOnProperty(prefix = "token.interceptor",name = "enable",matchIfMissing = true)
public class TokenInteceptorAutoConfigure {
    /**
     * 向容器注入webmvc配置类
     * @param properties
     * @param tokenTemplate
     * @return
     */
    @Bean
    public WebMvcConfigurer webMvcConfigurer(TokenInterceptorProperties properties, TokenTemplate tokenTemplate) {
        TokenWebConfig webConfig = new TokenWebConfig(properties,tokenTemplate);
        return  webConfig;
    }
}
